package leetcode.N1_N100;

/**
 * @author xiwai [hww282306@alibaba-inc.com]
 * @version 1.0
 * @date 2020/12/7 3:42 下午
 */
public class N66 {

    public int[] plusOne(int[] digits) {
        int length = digits.length;
        if (length == 0) {
            return digits;
        }
        int upValue = 1;
        for (int i = length - 1; i >= 0; i--) {
            int val = digits[i] + upValue;
            if (val < 10) {
                digits[i] = val;
                return digits;
            }
            digits[i] = val % 10;
        }
        int[] newDigits = new int[length + 1];
        newDigits[0] = 1;
        System.arraycopy(digits, 0, newDigits, 1, length - 1);
        return newDigits;
    }
}
